﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.UserCon.Locomotive.MainBase.TrainDepSys
{
    public partial class uc_Locomotive_MainBase_TrainDepSys_ManaForm : DevExpress.XtraEditors.XtraForm
    {
        public string _LoadID, _LoadTCID, _LoadTTID, _LoadType, _LoadDeep, _LoadLevel = "";

        private void uc_Locomotive_MainBase_TrainDepSys_ManaForm_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

        private void tb_Name_TextChanged(object sender, EventArgs e)
        {
            if (tb_Name.Text.Trim().Length > 0 && tb_Name1.Text.Trim().Length > 0 && tb_Code.Text.Trim().Length > 0 && tb_Num.Text.Trim().Length > 0 && tb_Indate.Text.Trim().Length > 0)
            {
                bt_Sure.Enabled = true;
            }
            else
            {
                bt_Sure.Enabled = false;
            }
        }

        private void bt_Sure_Click(object sender, EventArgs e)
        {
            string strSQL = "";
            string _strType = "9";
            foreach (Control _c in gb_Type.Controls)
            {
                if ((_c as RadioButton).Checked)
                {
                    _strType = _c.Tag.ToString();
                }
            }
            switch (_LoadType)
            {
                case "Add":
                    if (_LoadDeep == "-1")
                    {
                        strSQL = "insert into TS_S_T_P_TrainDepSys(f_name,f_name1,f_no,f_num,f_indate,f_workerid,f_deep,f_level,f_tcid,f_ttid,f_type) values('" + tb_Name.Text.Trim() + "','" + tb_Name1.Text.Trim() + "','" + tb_Code.Text.Trim() + "'," + tb_Num.Text.Trim() + "," + tb_Indate.Text.Trim() + "," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",0,','," + _LoadTCID + "," + _LoadTTID + "," + _strType+")";
                    }
                    else
                    {
                        strSQL = "insert into TS_S_T_P_TrainDepSys(f_name,f_name1,f_no,f_num,f_indate,f_workerid,f_deep,f_level,f_tcid,f_ttid,f_type) values('" + tb_Name.Text.Trim() + "','" + tb_Name1.Text.Trim() + "','" + tb_Code.Text.Trim() + "'," + tb_Num.Text.Trim() + "," + tb_Indate.Text.Trim() + "," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + "," + (Convert.ToInt32(_LoadDeep) + 1).ToString() + ",'" + _LoadLevel + _LoadID + ",'," + _LoadTCID + "," + _LoadTTID + "," + _strType+")";
                    }
                    break;
                case "Edit":
                    strSQL = "update TS_S_T_P_TrainDepSys set f_name='" + tb_Name.Text.Trim() + "',f_name1='" + tb_Name1.Text.Trim() + "',f_no='" + tb_Code.Text.Trim() + "',f_num=" + tb_Num.Text.Trim() + ",f_indate=" + tb_Indate.Text.Trim() + ",f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate(),f_type="+_strType+" where f_id="+_LoadID;
                    break;
                case "Del":
                    strSQL = "update TS_S_T_P_TrainDepSys set f_del=1,f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + _LoadID;
                    break;
            }
            TS_Win_Class.MySqlCom(strSQL);
            this.DialogResult = DialogResult.OK;
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void uc_Locomotive_MainBase_TrainDepSys_ManaForm_Load(object sender, EventArgs e)
        {
            switch (_LoadType)
            {
                case "Add":
                    bt_Sure.Text = "确定增加";
                    break;
                case "Edit":
                    bt_Sure.Text = "确定修改";
                    break;
                case "Del":
                    bt_Sure.Text = "确定删除";
                    break;
            }
            if (_LoadType == "Add")
            {

            }
            else
            {
                string[] _str = TS_Win_Class.GetSQlFieldValue("select * from TS_S_T_P_TrainDepSys where f_id=" + _LoadID, new string[] { "f_name", "f_name1", "f_no","f_num", "f_indate", "f_type" });
                tb_Name.Text = _str[0];
                tb_Name1.Text = _str[1];
                tb_Code.Text = _str[2];
                tb_Num.Text = _str[3];
                tb_Indate.Text = _str[4];
                foreach(Control _c in gb_Type.Controls )
                {
                    if (_c.Tag.ToString()== _str[5])
                    {
                        (_c as RadioButton).Checked = true;
                    }
                }
            }
        }

        public uc_Locomotive_MainBase_TrainDepSys_ManaForm()
        {
            InitializeComponent();
        }
    }
}